package map.asteroids;

import gameStates.absGamesStates.AbsIngameState;

import networking.messages.syncMessages.ValueType;

import com.jme.scene.Node;

public class ResourceAsteroid extends Asteroid {
	
	private static final long serialVersionUID = 1L;
	
	private float maxResources;
	
	public ResourceAsteroid(String modelPath, String title, Node model, int maxResources, 
			AsteroidField field, int asteroidID, AbsIngameState ingameState) {
		super(modelPath, title, model, field, asteroidID, ingameState);
		this.maxResources = maxResources;
		
		initValueContainer();
	}
	
	protected void initValueContainer() {
		valueManager.changeValue(ValueType.Resources, maxResources);
	}
	
	private void changeResources(float newResources) {
		if(newResources == getCurrentResources()) return;
		
		valueManager.changeValue(ValueType.Resources, newResources);
	}
	
	public float getCurrentResources() { return valueManager.getFloatValue(ValueType.Resources); }
	
	public boolean isEmpty() { return getCurrentResources() == 0; }
	
	public void harvest(float amount) {
		float currentResources = getCurrentResources();
		if(currentResources - amount < 0) amount = currentResources;
		changeResources(currentResources - amount);
	}
}